package com.leetcode.partition7;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/17 9:58
 */
public class LC688骑士在棋盘上的概率 {

    private static final int N = 30, K = 110;
    private static final int[][] dirs = {{-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}, {1, 2}, {2, 1}, {2, -1}, {1, -2}};
    //f[i][j][k]表示在位置(i,j)还有k步的情况下有多少几率不跳出棋盘
    private static double[][][] f = new double[N][N][K];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), k = Integer.parseInt(ss[1]), row = Integer.parseInt(ss[2]), col = Integer.parseInt(ss[3]);
        writer.write(knightProbability(n, k, row, col) + "\n");
        writer.flush();
    }

    public static double knightProbability(int n, int k, int row, int column) {
        //所有位置中如果只能跳0步，一定不会跳出棋盘
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) f[i][j][0] = 1;
        }
        //当前位置的概率等于能跳到的其它位置的概率和 f[i][j][k]=sum(其它8个位置)/8
        for (int x = 1; x <= k; x++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    for (int[] dir : dirs) {
                        int nx = i + dir[0], ny = j + dir[1];
                        if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
                        f[i][j][x] += f[nx][ny][x - 1];
                    }
                    f[i][j][x] /= 8;
                }
            }
        }
        return f[row][column][k];
    }
}
